package love.yuanmengrobot.als.system.servlet;

import love.yuanmengrobot.als.utilPublic.JdbcUtil;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class InitServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Override
    public void init(ServletConfig config) {
        try {
            super.init();
        } catch (ServletException e) {
            e.printStackTrace();
        }
        System.out.println("================>[Servlet]自动加载启动开始:预计耗时15s<================");
        long startTime=System.currentTimeMillis();
        // 读取Spring容器中的Bean[此时Bean已加载,可以使用]
        //执行想要的代码
        Connection conn = null;
        PreparedStatement rs = null;
        try {
            conn = JdbcUtil.getConnection();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        JdbcUtil.close(rs, conn);
        long endTime=System.currentTimeMillis();
        System.out.println("================>[Servlet]自动加载启动结束:实际耗时"+(endTime-startTime)/1000+"s<================");
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
